import pick from "lodash.pick";

export default {
    // 表单字段
    props: {
        //是否显示model
        visible: {
            type: Boolean,
            required: true
        },
        //是否显示加载状态
        loading: {
            type: Boolean,
            default: () => false
        },
        //数据
        model: {
            type: Object,
            default: () => null
        }
    },
    data(){
        return{
            form: this.$form.createForm(this),
            //model 标题
            title: '',
            //当前表单操作
            action: this.SYS_CONST.FORM_ACTION.NONE,
            //验证规则
            decoratorValidateRules:{},
            //表单布局
            formLayout :{
                labelCol: {
                    xs: { span: 24 },
                    sm: { span: 7 }
                },
                wrapperCol: {
                    xs: { span: 24 },
                    sm: { span: 13 }
                }
            }
        }
    },
    methods:{
        //编辑一些基本属性
        editOptions(options){
            console.log(options)
            this.title=options.title;
            this.action=options.action
        }
    },
    created(){
        // 当 model 发生改变时，为表单设置值
        this.$watch('model', () => {
            this.model && this.form.setFieldsValue(pick(this.model, Object.keys(this.form.getFieldsValue())))
        })
    }


}